package com.efast.dmom.mes.datahandlers.entity;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.efast.dmom.mes.bean.QualityGroup;
import com.efast.dmom.mes.bean.ResultBean;
import com.efast.dmom.mes.dao.entity.QualityGroupDao;
import com.efast.dmom.mes.datahandlers.base.QualityBaseDataHandler;
import com.efast.dmom.mes.entity.QualityGroupEntity;
import com.efast.dmom.mes.util.SpringWebUtils;
import com.efast.dmom.mes.util.TimeUtil;
@Component
public class QualityGroupHandler extends QualityBaseDataHandler<QualityGroup>{

	
	@Autowired
	private QualityGroupDao qualityGroupDao;
	
	
	@Override
	public ResultBean save(QualityGroup obj) {
		ResultBean resultBean = new ResultBean();
		
		obj.getInnerData().setSiteId(DataHandlerUtils.getSiteId());
		obj.getInnerData().setCreationTime(TimeUtil.getLocalDateTime());
		obj.getInnerData().setCreationTimeZone(TimeUtil.getLocalTimeZone());
		obj.getInnerData().setCreator(SpringWebUtils.getRequestUser());
		obj.getInnerData().setLastModifiedTime(TimeUtil.getLocalDateTime());
		obj.getInnerData().setLastModifiedTimeZone(TimeUtil.getLocalTimeZone());
		obj.getInnerData().setLastModifier(SpringWebUtils.getRequestUser());
//	    obj.getInnerData().setCreationPid(DataHandlerUtils.getDmomPid());
//	    obj.getInnerData().setLastModifiedPid(DataHandlerUtils.getDmomPid());
		obj.getInnerData().setRowStatus(1);
		obj.getInnerData().setRowTrxId(1);
		qualityGroupDao.save(obj.getInnerData());
		
		return resultBean;
	}
	
	@Override
	public ResultBean update(QualityGroup obj) {
		ResultBean resultBean = new ResultBean();
		
		obj.getInnerData().setLastModifiedTime(TimeUtil.getLocalDateTime());
		obj.getInnerData().setLastModifiedTimeZone(TimeUtil.getLocalTimeZone());
		obj.getInnerData().setLastModifier(SpringWebUtils.getRequestUser());
//	    obj.getInnerData().setLastModifiedPid(DataHandlerUtils.getDmomPid());
		obj.getInnerData().setRowTrxId(1);
		qualityGroupDao.update(obj.getInnerData());
		
		return resultBean;
	}

	public void batchDeleteByIds(List<QualityGroup> objs) {
		List<QualityGroupEntity> list = new ArrayList<QualityGroupEntity>();
		for (QualityGroup obj : objs) {
			obj.getInnerData().setLastModifiedTime(TimeUtil.getLocalDateTime());
			obj.getInnerData().setLastModifiedTimeZone(TimeUtil.getLocalTimeZone());
			obj.getInnerData().setLastModifier(SpringWebUtils.getRequestUser());
//		    obj.getInnerData().setLastModifiedPid(DataHandlerUtils.getDmomPid());
			obj.getInnerData().setRowTrxId(1);	
			list.add(obj.getInnerData());
		}
		qualityGroupDao.deleteBatch(list);
	}

	public QualityGroup getById(long id) {
		 QualityGroup qualityGroup = new QualityGroup();
		 qualityGroup.setInnerData(qualityGroupDao.getById(id));
		return qualityGroup;
	}

	public QualityGroup getByName(String name) {
		 QualityGroup qualityGroup = new QualityGroup();
		 qualityGroup.setInnerData(qualityGroupDao.getByName(name));
		return qualityGroup;
	}

	public QualityGroup getByCode(String partGroupCode) {
		QualityGroup qualityGroup = new QualityGroup();
		qualityGroup.setInnerData(qualityGroupDao.getByCode(partGroupCode));
		return qualityGroup;
	}

	@Override
	public void batchDeleteById(List<QualityGroup> list) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public ResultBean delete(QualityGroup obj) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public ResultBean saveBatch(List<QualityGroup> obj) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public ResultBean updateBatch(List<QualityGroup> obj) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public ResultBean deleteBatch(List<QualityGroup> obj) {
		// TODO Auto-generated method stub
		return null;
	}




}
